/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-03-23     jianhong       the first version
 */
#ifndef APPLICATIONS_LCD_DRIVER_H_
#define APPLICATIONS_LCD_DRIVER_H_
#include <rtthread.h>
#include "board.h"

//-------------------------屏幕物理像素设置--------------------------------------//
#define LCD_X_SIZE          240
#define LCD_Y_SIZE          320

/////////////////////////////////////用户配置区///////////////////////////////////
//支持横竖屏快速定义切换
#define USE_HORIZONTAL          1   //定义是否使用横屏      0,不使用.1,使用.

#ifdef USE_HORIZONTAL//如果定义了横屏
#define X_MAX_PIXEL         LCD_Y_SIZE
#define Y_MAX_PIXEL         LCD_X_SIZE
#else
#define X_MAX_PIXEL         LCD_X_SIZE
#define Y_MAX_PIXEL         LCD_Y_SIZE
#endif
//////////////////////////////////////////////////////////////////////////////////

#define RED     0xf800
#define GREEN   0x07e0
#define BLUE    0x001f
#define WHITE   0xffff
#define BLACK   0x0000
#define YELLOW  0xFFE0
#define GRAY0   0xEF7D      //灰色0 3165 00110 001011 00101
#define GRAY1   0x8410          //灰色1      00000 000000 00000
#define GRAY2   0x4208          //灰色2  1111111111011111

//本测试程序使用的是模拟SPI接口驱动
/******************************************************************************
*******************************************************************************/
extern uint8_t LCD_LED;     //PA.7--->>TFT --BL
extern uint8_t LCD_RS;      //PF.1--->>TFT --RS/DC
extern uint8_t LCD_CS;      //PA.0--->>TFT --CS/CE
extern uint8_t LCD_RST;     //PA.5-->>TFT --RST
extern uint8_t LCD_SCL;     //PA.1--->>TFT --SCL/SCK
extern uint8_t LCD_SDA;     //PF.0 MOSI--->>TFT --SDA/DIN


//#define LCD_CS_SET(x) LCD_CTRL->ODR=(LCD_CTRL->ODR&~LCD_CS)|(x ? LCD_CS:0)

//液晶控制口置1操作语句宏定义
#define LCD_CS_SET      rt_pin_write(LCD_CS, PIN_HIGH)
#define LCD_RS_SET      rt_pin_write(LCD_RS, PIN_HIGH)
#define LCD_SDA_SET     rt_pin_write(LCD_SDA, PIN_HIGH);
#define LCD_SCL_SET     rt_pin_write(LCD_SCL, PIN_HIGH);
#define LCD_RST_SET     rt_pin_write(LCD_RST, PIN_HIGH);
#define LCD_LED_SET     rt_pin_write(LCD_LED, PIN_HIGH);

//液晶控制口置0操作语句宏定义
#define LCD_CS_CLR      rt_pin_write(LCD_CS, PIN_LOW)
#define LCD_RS_CLR      rt_pin_write(LCD_RS, PIN_LOW)
#define LCD_SDA_CLR     rt_pin_write(LCD_SDA, PIN_LOW)
#define LCD_SCL_CLR     rt_pin_write(LCD_SCL, PIN_LOW)
#define LCD_RST_CLR     rt_pin_write(LCD_RST, PIN_LOW)
#define LCD_LED_CLR     rt_pin_write(LCD_LED, PIN_LOW)


void LCD_GPIO_Init(void);
void Lcd_WriteIndex(uint8_t Index);
void Lcd_WriteData(uint8_t Data);
void Lcd_WriteReg(uint8_t Index,uint8_t Data);
uint16_t Lcd_ReadReg(uint8_t LCD_Reg);
void Lcd_Reset(void);
void Lcd_Init(void);
void Lcd_Clear(uint16_t Color);
void Lcd_SetXY(uint16_t x,uint16_t y);
void Gui_DrawPoint(uint16_t x,uint16_t y,uint16_t Data);
unsigned int Lcd_ReadPoint(uint16_t x,uint16_t y);
void Lcd_SetRegion(uint16_t x_start,uint16_t y_start,uint16_t x_end,uint16_t y_end);
void Lcd_WriteData_16Bit(uint16_t Data);


#endif /* APPLICATIONS_LCD_DRIVER_H_ */
